package com.ssl.basics.thread;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * 描述：
 *
 * @author shi_senlin
 * @create 2021/07/10 12:33
 */
@Slf4j(topic = "com.ssl.thread")
public class ThreadCreate {

    static class ThreadRunable implements Runnable {
        @Override
        public void run() {
            log.info("{}创建方式：实现Runnable接口...", Thread.currentThread().getName());
        }
    }

    static class Threadcallable implements Callable<Integer> {
        @Override
        public Integer call() throws Exception {
            log.info("{}创建方式：通过实现Callable接口，然后传给FutureTask，再传给Thread的方式实现...", Thread.currentThread().getName());
            return 1024;
        }
    }

    static class ThreadExtends extends Thread {
        @Override
        public void run() {
            super.run();
            log.info("{} 创建方式：继承Threaad类...", Thread.currentThread().getName());
        }
    }

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            log.info("{} 创建方式：匿名内部类方式，实现Runnable接口...", Thread.currentThread().getName());
        }, "t1");

        Thread t2 = new Thread(new ThreadRunable(), "t2");

        FutureTask<Integer> futureTask = new FutureTask<>(new Threadcallable());
        Thread t3 = new Thread(futureTask, "t3");

        Thread t4 = new Thread(new ThreadExtends(), "t4");
        t1.start();
        t2.start();
        t3.start();
        t4.start();
    }
}
